import React, { Component } from 'react'
import { Button, FlatList, Text, View } from 'react-native'
import StuShow from './StuShow'

let url="http://172.16.1.151:3000/stus"
export default class Home extends Component {
    state={stus:[]}

    componentDidMount(){
        this.props.navigation.addListener('focus',()=>console.log('focus....'))
        fetch(url)
        .then(resp=>resp.json())
        .then(stus=>this.setState({stus}))
    }
    _renderStu=({item})=><StuShow stu={item}/>
    _add=()=>{
        this.props.navigation.navigate("StuAddor")
    }
    render() {
        return (
            <View>
                <Button title="添加" onPress={this._add}/>
                <FlatList data={this.state.stus} renderItem={this._renderStu} 
                keyExtractor={stu=>stu.id}/>
            </View>
        )
    }
}
